<?php
Class Model extends CI_Model
{
	function get_data($table, $fields, $relation, $where)
	{
		$this->db->select($fields);
		$this->db->from($table);
		if(count($relation['table'])){
			for($i=0;$i<count($relation['table']);$i++){
				$join = $relation['table'][$i].'.'.$relation['id'][$i].'='.$table.'.'.$relation['id'][$i];
				$this->db->join($relation['table'][$i], $join, 'inner');
			}
		}
		if(isset($where)) $this->db->where($where);
		$query = $this->db->get();

		if($query -> num_rows() > 0) {
			return $query->result();
		} else {
			return array();
		}
	}
	
	function get_data_by_id($table, $where){
		$this->db->select('*');
		$this->db->from($table);
		$this->db->where($where);
		
		$query = $this->db->get();
		return $query->row();
	}
	
	function insert($table, $value){
		$tambah = $this->db->insert($table, $value);
		return $tambah;
	}
}
?>